
import 'package:flutter/material.dart';
import 'package:flutterlib/common/constants/constants.dart';
import 'package:flutterlib/common/net/dao_result.dart';
import 'package:flutterlib/common/net/retrofit/activity_api.dart';
import 'package:flutterlib/common/utils/navigator_utils.dart';
import 'package:flutterlib/common/utils/toast.dart';
import 'package:flutterlib/model/activity/activity.dart';
import 'package:flutterlib/model/activity/activity_page_new_query.dart';
import 'package:flutterlib/model/activity/activity_page_query.dart';
import 'package:flutterlib/widgets/bussiness/activity/activity_list_item_new_admin.dart';

import '../post_list_widget_page.dart';

class ActivityNormalListWidgetPage extends PostListWidgetPage {
  final String name;
  final int interestId;
  final int type;

  ActivityNormalListWidgetPage({this.name, this.interestId, this.type, Key key})
      : super(key: key);

  @override
  ActivityNormalListWidgetPageState createState() => ActivityNormalListWidgetPageState();
}

///页面 KeepAlive ，同时支持 动画Ticker
class ActivityNormalListWidgetPageState extends PostListWidgetPageState<ActivityNormalListWidgetPage>
    {

  getDataLogic(int page) async {
    print(page);
    if(widget.type == 2){
      print(page);
      var activitys = await ActivityApi.builder().pageByQuery(
        ActivityPageQuery(
          interestId: 0,
          type: 1,
          pageNum: page,
        ),

      );
      return new DataResult(activitys.list, true);
    }
    if(widget.type == 3){
      print(page);
      var activitys = await ActivityApi.builder().pageByQuery(
        ActivityPageQuery(
          interestId: 0,
          type: 2,
          pageNum: page,
        ),

      );
      return new DataResult(activitys.list, true);
    }
  }

  Widget renderItem(index, activity) {
    //提交
    // var post = pullLoadWidgetControl.dataList[index];
    return
      ActivityListItemNewAdmin(activity,  onPressed: () {
        NavigatorUtils.gotoActivityDetail(context, activity.id);
      }, onPassPressed: ()async{
      if(!isLogin){
        NavigatorUtils.goLogin(context);
        return false;
      }
      Activity listItem = manger.getListItem(index);
      if(listItem.status == 0) {
        await ActivityApi.builder().updateStatus(listItem.id, 1);
        ToastUtils.success("通过成功");
        manger.notifyDataSetChange(() {
          listItem.status = 1;
        });
      }
    }, onRejectPressed: ()async{
      if(!isLogin){
        NavigatorUtils.goLogin(context);
        return false;
      }
      Activity listItem = manger.getListItem(index);
      if(listItem.status == 0) {
        await ActivityApi.builder().updateStatus(listItem.id, 3);
        ToastUtils.success("拒绝成功");
        manger.notifyDataSetChange(() {
          listItem.status = 3;
        });
      }
    });
  }

  @override
  List<Widget> renderHeader(BuildContext context, bool innerBoxIsScrolled) {
    List<Widget> widgets = [];

    return widgets;
  }

}
